package com.lei.session.service.impl;

import com.lei.session.dao.UserDao;
import com.lei.session.dao.impl.UserDaoImpl;
import com.lei.session.entity.LoginLog;
import com.lei.session.service.LoginLogService;
import com.lei.session.service.UserService;

public class UserServiceImpl implements UserService {
	private UserDao useDao = new UserDaoImpl();
	private LoginLogService loginLogService = new LoginLogServiceImpl();
	@Override
	
		public boolean login(String userName, String password,String ip) {
			boolean success = useDao.login(userName, password);
			LoginLog loginLog = buildLoginLog(userName, success,ip);
			loginLogService.add(loginLog);
			return success;
		}
		private LoginLog buildLoginLog(String userName, boolean success,String ip) {
			LoginLog loginLog = new LoginLog();
			loginLog.setStatus(success?"1":"2");
			loginLog.setUserName(userName);
			loginLog.setIp(ip);
			return loginLog;
		}
	}


